﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace EstateNuke.Data
{
    public partial class Role
    {
        #region Fileds & Properties

        /// <summary>
        /// </summary>
        public string DisplayName
        {
            get
            {
                return string.Format("{0}{1}", Name, IsDeleted ? " (已删除)" : "");
            }
        }

        /// <summary>
        /// </summary>
        public IList<User> Users
        {
            get
            {
                return InternalUsers.Where(user => user.IsDeleted == false).ToList();
            }
        }

        #endregion

        #region Delete

        ///// <summary>
        ///// </summary>
        //public void Delete(User modifiedUser)
        //{
        //    if (modifiedUser == null)
        //    {
        //        throw new ArgumentNullException("modifiedUser");
        //    }
        //    IsDeleted = true;
        //    ModifiedDate = DateTime.Now;
        //    ModifiedByUser = modifiedUser;
        //}

        ///// <summary>
        ///// </summary>
        //public void CancelDelete(User modifiedUser)
        //{
        //    if (modifiedUser == null)
        //    {
        //        throw new ArgumentNullException("modifiedUser");
        //    }
        //    IsDeleted = false;
        //    ModifiedDate = DateTime.Now;
        //    ModifiedByUser = modifiedUser;
        //}

        #endregion
    }

    public class RoleEnum
    {
        #region Fields & Properties

        private readonly EstateNukeCore _context;

        private Role _administrator;

        /// <summary>
        /// </summary>
        public Role Administrator
        {
            get
            {
                return _administrator ?? (_administrator = _context.Roles.FirstOrDefault(role => role.Id == 1));
            }
        }

        private Role _generalManager;

        /// <summary>
        /// </summary>
        public Role GeneralManager
        {
            get
            {
                return _generalManager ?? (_generalManager = _context.Roles.FirstOrDefault(role => role.Id == 2));
            }
        }

        private Role _projectsDirector;

        /// <summary>
        /// </summary>
        public Role ProjectsDirector
        {
            get
            {
                return _projectsDirector ?? (_projectsDirector = _context.Roles.FirstOrDefault(role => role.Id == 3));
            }
        }

        private Role _projectManager;

        /// <summary>
        /// </summary>
        public Role ProjectManager
        {
            get
            {
                return _projectManager ?? (_projectManager = _context.Roles.FirstOrDefault(role => role.Id == 4));
            }
        }

        private Role _projectAssistant;

        /// <summary>
        /// </summary>
        public Role ProjectAssistant
        {
            get
            {
                return _projectAssistant ?? (_projectAssistant = _context.Roles.FirstOrDefault(role => role.Id == 5));
            }
        }

        private Role _developerRepresentitive;

        /// <summary>
        /// </summary>
        public Role DeveloperRepresentitive
        {
            get
            {
                return _developerRepresentitive ?? (_developerRepresentitive = _context.Roles.FirstOrDefault(role => role.Id == 6));
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// </summary>
        /// <param name = "context"></param>
        public RoleEnum(EstateNukeCore context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            _context = context;
        }

        #endregion
    }
}